﻿using Engine.Graphics.Shaders.Wr2Shaders;
using SharpDX.Direct3D11;
using System.Collections.Generic;

namespace Engine.Graphics.Shaders
{
    public class Wr2ShaderArray
    {
        #region Private Fields

        private Material000 material000;
        private Material016 material016;
        private Material032 material032;
        private Material048 material048;
        private Material064 material064;
        private Material080 material080;
        private Material096 material096;
        private Material112 material112;
        private Material128 material128;
        private Material144 material144;
        private Material160 material160;
        private Material176 material176;
        private Material192 material192;
        private Material208 material208;
        private Material224 material224;
        private Material240 material240;
        private List<ISetShaderValues> registeredShaders;

        #endregion Private Fields

        #region Public Constructors

        public Wr2ShaderArray(Device device, MaterialManager materialManger, string shaderpath)
        {
            shaderpath += "\\WorldRacing2\\";
            this.registeredShaders = new List<ISetShaderValues>();
            LoadShaders(shaderpath, device);
        }

        #endregion Public Constructors

        #region Public Methods

        public List<ISetShaderValues> GetRegisteredShaders()
        {
            return this.registeredShaders;
        }

        public ShaderBase SetEffectValues(int materialID, MaterialManager materialManager)
        {
            Material material = materialManager.GetMaterial(materialID);

            switch ((EnumMappingMode)material.MappingMode)
            {
                case EnumMappingMode.material00:
                case EnumMappingMode.material02:
                    material000.SetProperties(materialID, materialManager);
                    return material000;

                case EnumMappingMode.material16:
                    material016.SetProperties(materialID, materialManager);
                    return material016;

                case EnumMappingMode.material32:
                    material032.SetProperties(materialID, materialManager);
                    return material032;

                case EnumMappingMode.material48:
                    material048.SetProperties(materialID, materialManager);
                    return material048;

                case EnumMappingMode.material64:
                    material064.SetProperties(materialID, materialManager);
                    return material064;

                case EnumMappingMode.material80:
                    material080.SetProperties(materialID, materialManager);
                    return material080;

                case EnumMappingMode.material96:
                    material096.SetProperties(materialID, materialManager);
                    return material096;

                case EnumMappingMode.material112:
                    material112.SetProperties(materialID, materialManager);
                    return material112;

                case EnumMappingMode.material128:
                    material128.SetProperties(materialID, materialManager);
                    return material128;

                case EnumMappingMode.material144:
                    material144.SetProperties(materialID, materialManager);
                    return material144;

                case EnumMappingMode.material160:
                    material160.SetProperties(materialID, materialManager);
                    return material160;

                case EnumMappingMode.material176:
                    material176.SetProperties(materialID, materialManager);
                    return material176;

                case EnumMappingMode.material192:
                    material192.SetProperties(materialID, materialManager);
                    return material192;

                case EnumMappingMode.material208:
                    material208.SetProperties(materialID, materialManager);
                    return material208;

                case EnumMappingMode.material224:
                    material224.SetProperties(materialID, materialManager);
                    return material224;

                case EnumMappingMode.material240:
                    material240.SetProperties(materialID, materialManager);
                    return material240;

                default:
                    // throw new Exception("Set effect value is not implemented");
                    material000.SetProperties(materialID, materialManager);
                    return material000;
            }
        }

        #endregion Public Methods

        #region Private Methods

        private void LoadShaders(string shaderPath, Device device)
        {
            //Load
            this.material000 = new Material000(device, shaderPath);
            this.material016 = new Material016(device, shaderPath);
            this.material032 = new Material032(device, shaderPath);
            this.material048 = new Material048(device, shaderPath);
            this.material064 = new Material064(device, shaderPath);
            this.material080 = new Material080(device, shaderPath);
            this.material096 = new Material096(device, shaderPath);
            this.material112 = new Material112(device, shaderPath);
            this.material128 = new Material128(device, shaderPath);
            this.material144 = new Material144(device, shaderPath);
            this.material160 = new Material160(device, shaderPath);
            this.material176 = new Material176(device, shaderPath);
            this.material192 = new Material192(device, shaderPath);
            this.material208 = new Material208(device, shaderPath);
            this.material224 = new Material224(device, shaderPath);
            this.material240 = new Material240(device, shaderPath);

            this.registeredShaders.Clear();
            this.registeredShaders.Add(this.material000);
            this.registeredShaders.Add(this.material016);
            this.registeredShaders.Add(this.material032);
            this.registeredShaders.Add(this.material048);
            this.registeredShaders.Add(this.material064);
            this.registeredShaders.Add(this.material080);
            this.registeredShaders.Add(this.material096);
            this.registeredShaders.Add(this.material112);
            this.registeredShaders.Add(this.material128);
            this.registeredShaders.Add(this.material144);
            this.registeredShaders.Add(this.material160);
            this.registeredShaders.Add(this.material176);
            this.registeredShaders.Add(this.material192);
            this.registeredShaders.Add(this.material208);
            this.registeredShaders.Add(this.material224);
            this.registeredShaders.Add(this.material240);
        }

        #endregion Private Methods
    }
}